<?php
class product {
	private $id;
	private $name;
	private $description;
	private $content;
	private $image;
	private $image2;
	private $image3;
	private $image4;
	private $catid;
	private $date;
	private $status;
	private $tinhtrang;
	private $banchay;
	private $tieubieu;
	private $url_rewrite;
	

	public function setid($id) {
		$this->id = $id;
	}
	public function getid() {
		return $this->id;
	}
	// set get name
	public function setname($name) {
		$this->name = $name;
	}
	public function getname() {
		return $this->name;
	}
	// set get description
	public function setdescription($description) {
		$this->description = $description;
	}
	public function getdescription() {
		return $this->description;
	}
	// 	set get content
	public function setcontent($content) {
		$this->content = $content;
	}
	public function getcontent() {
		return $this->content;
	}
	// set get images
	public function setimage($image) {
		$this->image = $image;
	}
	public function getimage() {
		return $this->image;
	}
	// set get images 2
	public function setimage2($image2) {
		$this->image2 = $image2;
	}
	public function getimage2() {
		return $this->image2;
	}
	// set get images 3
	public function setimage3($image3) {
		$this->image3 = $image3;
	}
	public function getimage3() {
		return $this->image3;
	}
// set get images 4
	public function setimage4($image4) {
		$this->image4 = $image4;
	}
	public function getimage4() {
		return $this->image4;
	}
	// set get catid
	public function setcatid($catid) {
		$this->catid = $catid;
	}
	public function getcatid() {
		return $this->catid;
	}
	// set get date
	public function setdate($date) {
		$this->date = $date;
	}
	public function getdate() {
		return $this->date;
	}
	// set get status
	public function setstatus($status) {
		if ($status) $this->status = 1;
	}
	public function getstatus() {
		return $this->status;
	}
	// set get tinhtrang
	public function settinhtrang($tinhtrang) {
		$this->tinhtrang = $tinhtrang;
	}
	public function gettinhtrang() {
		return $this->tinhtrang;
	}
	// set get banchay
	public function setbanchay($banchay) {
		$this->banchay = $banchay;
	}
	public function getbanchay() {
		return $this->banchay;
	}
	// set get tieubieu
	public function settieubieu($tieubieu) {
		$this->tieubieu = $tieubieu;
	}
	public function gettieubieu() {
		return $this->tieubieu;
	}
	// set get url_rewrite
	public function setrewrite($url_rewrite) {
		$this->url_rewrite = $url_rewrite;
	}
	public function getrewrite() {
		return $this->url_rewrite;
	}
	

	public function getone() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "product where id='" . $this->id . "'";
		$return = $db->executeQuery ( $sql, 2 );
		return $return;
	}
	
	// insert product
	public function insert(){
		GLOBAL $db;
		//$arr['id'] = $this->getid();
		$arr['name'] = $this->getname();
		$arr['description'] = $this->getdescription();
		$arr['content'] = $this->getcontent();
		$arr['image'] = $this->getimage();
		$arr['image2'] = $this->getimage2();
		$arr['image3'] = $this->getimage3();
		$arr['cat_id'] = $this->getcatid();
		$arr['date'] = $this->getdate();
		$arr['status'] = $this->getstatus();
		$arr['tinhtrang'] = $this->gettinhtrang();
		$arr['banchay'] = $this->getbanchay();
		$arr['tieubieu'] = $this->gettieubieu();
		$arr['url_rewrite'] = $this->getrewrite();		
		$db->record_insert($db->tbl_fix."product", $arr);
	}
	// List all product
	public function listall() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "product";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function listbycat() {
		GLOBAL $db;
		$sql = "SELECT * FROM " . $db->tbl_fix . "product where cat_id='".$this->catid."'";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	// 	List all product
	public function top5cat() {
		GLOBAL $db;
		if ($this->catid != '')	$catid = " and cat_id='".$this->catid."' ";
		$sql = "SELECT * FROM " . $db->tbl_fix . "product where 1=1 ".$catid." limit 5";
		$result = $db->executeQuery ( $sql );
		while ( $rows = mysql_fetch_array ( $result ) ) {
			$return [] = $rows;
		}
		return $return;
	}
	public function delete() {
		GLOBAL $db;
		$sql = "DELETE FROM " . $db->tbl_fix . "product where `id` ='" . $this->id . "'";
		$db->executeQuery ( $sql );
	}

}
$pro = new product ();
?>